﻿using Keyer.DataBase.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace Keyer.DataBase.Mapping.Sqlite
{
    public class AppMap : EntityTypeConfiguration<sys_app>  
    {
        public AppMap()
        {
            // 表名
            this.ToTable("App");

            // 主键
            this.HasKey(t => t.id);

            // 属性设置
            //this.Property(t => t.id)
            //   .HasColumnName("id")
            //   .HasMaxLength(40);
            this.Property(t => t.name)
                .HasColumnName("name")
                .HasMaxLength(40)
                .IsRequired();
            this.Property(t => t.appUrl)
                 .HasColumnName("appUrl")
                 .HasMaxLength(120)
                 .IsRequired();
            this.Property(t => t.imgUrl)
                 .HasColumnName("imgUrl")
                 .HasMaxLength(120)
                 .IsRequired();
            this.Property(t => t.basicdataId)
                .HasColumnName("basicdataId");

            //Base属性设置            
            this.Property(t => t.createUser)
                .HasColumnName("createUser")
                .HasMaxLength(20);
            this.Property(t => t.createTime)
                 .HasColumnName("createTime");
            this.Property(t => t.rowVersion)
                .HasColumnName("rowVersion")
                .IsRowVersion();

            // 关联设置
            this.HasRequired(t => t.basicdata)
                .WithMany(t => t.apps)
                .HasForeignKey(t => t.basicdataId)
                .WillCascadeOnDelete(false);
        }
    }
}
